package 代码随想2._2链表;

/**
 * @author XXX
 * @date 2024-01-14 13:03
 */

import 代码随想录.二叉树.Node;

/**
 * https://leetcode.cn/problems/remove-linked-list-elements/description/
 */
class Test{

}

public class _1移除链表元素 {
    public ListNode removeElements(ListNode head, int val) {
        if(head == null)
            return  null;
        ListNode newhead = new ListNode(-1);
        newhead.next = head;
        ListNode pre = newhead;
        ListNode cur = head;
        while (cur !=null){
            if(cur.val == val){
                pre.next = cur.next;
            }else{
                pre = cur;
            }
            cur = cur.next;
        }
        return newhead.next;
    }
}
